/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Core.Model.Groups;
using Parser;
using XMHEGDecoder.Builders.Visibles;

namespace XMHEGDecoder.Builders
{
    public class ApplicationBuilder
    {
        public static void Build ( XmlElement node, Application app )
        {
            GroupBuilder.Build( node, app );

            #region  Add our attributes
            XmlElement e = node ["on-spawn-close-down"];
            if ( e != null )
                app.OnSpawnCloseDown = ActionBuilder.Build( e );

            e = node ["on-restart"];
            if ( e != null )
                app.OnRestart = ActionBuilder.Build( e );

            e = node ["default-attributes"];
            if ( e != null )
                BuildDefaultAttributes( e, app );

            #endregion
        }

        private static void BuildDefaultAttributes ( XmlElement node, Application app )
        {

            foreach ( XmlElement e in node.ChildNodes )
            {
                switch ( e.FirstChild.Name )
                {
                    case ( "character-set" ):
                        app.CharacterSet = DecodeUtils.ParseInt( e.FirstChild.InnerText );
                        break;
                    case ( "background-colour" ):
                        app.OriginalBackgroundColour = ColourBuilder.Build( e ["background-colour"] );
                        break;
                    case ( "text-colour" ):
                        app.OriginalTextColour = ColourBuilder.Build( e ["text-colour"] );
                        break;
                    case ( "font-attributes" ):
                        app.OriginalFontAttributes = TextBuilder.FontAttributesBuilder( e ["font-attributes"] );
                        break;
                    case ( "bitmap-content-hook" ):
                        app.BitmapContentHook = DecodeUtils.ParseInt( e.FirstChild.InnerText );
                        break;
                    case ( "stream-content-hook" ):
                        app.StreamContentHook = DecodeUtils.ParseInt( e.FirstChild.InnerText );
                        break;
                    case ( "text-content-hook" ):
                        app.TextContentHook = DecodeUtils.ParseInt( e.FirstChild.InnerText );
                        break;
                    case ( "line-art-content-hook" ):
                        app.LineArtContentHook = DecodeUtils.ParseInt( e.FirstChild.InnerText );
                        //throw new Exception( "1.06 does not allow content hook chnaged" );
                        break;
                    case ( "font" ):
                        break;

                    default:
                        break;

                }

            }

        }
    }
}
